package alkaid.eis.schedule.domain;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import lombok.experimental.UtilityClass;

/**
 * 任务信息查询条件
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class JobInfoSpecifications {
    public Specification<JobInfo> empty() {
        return (Root<JobInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return null;
        };
    }

    public Specification<JobInfo> beanNameLike(String beanName) {
        return (Root<JobInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.like(root.get("beanName"), "%" + beanName + "%");
        };
    }

    public Specification<JobInfo> remarkLike(String remark) {
        return (Root<JobInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.like(root.get("remark"), "%" + remark + "%");
        };
    }

    public Specification<JobInfo> enabledEqual(Boolean enabled) {
        return (Root<JobInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("enabled"), enabled);
        };
    }
}
